package com.ey12.service;

import java.util.ArrayList;
import java.util.List;

import com.ey12.db.dao.GmMoneyRecordDAO;
import com.ey12.db.domain.GmMoneyRecord;
import com.ey12.db.domain.GmUser;
import com.ey12.utils.DateUtil;

public class GmMoneyRecordService {
	private GmMoneyRecordDAO gmMoneyRecordDAO;

	public void setGmMoneyRecordDAO(GmMoneyRecordDAO gmMoneyRecordDAO) {
		this.gmMoneyRecordDAO = gmMoneyRecordDAO;
	}

	public GmMoneyRecordDAO getGmMoneyRecordDAO() {
		return gmMoneyRecordDAO;
	}
	public void creatValueCharge(GmMoneyRecord gmMoneyRecord){
		GmMoneyRecord gm = new GmMoneyRecord();
		gm.setGetType(new Integer(1));//1��ֵ2ȡ��
		gm.setState(new Integer(1)); 
		gm.setPayState(new Integer(0));//1δ����2�ɹ�
		gm.setGetMoney(gmMoneyRecord.getGetMoney());
		gm.setGmUser(gmMoneyRecord.getGmUser());
		gm.setCreateDate(new DateUtil().toTimeString());
		gm.setOrderNum(gmMoneyRecord.getOrderNum());
		System.out.println(new DateUtil().toGetOrderNum());
		gmMoneyRecordDAO.saveOrUpdate(gm);
	}
	public void creatCashDraw(GmMoneyRecord gmMoneyRecord,int i){
		GmMoneyRecord gm = new GmMoneyRecord();
		gm.setGetType(new Integer(2));
		gm.setState(new Integer(1));
		gm.setPayState(new Integer(0));
		gm.setGetMoney(gmMoneyRecord.getGetMoney());
		gm.setRealMoney(gmMoneyRecord.getRealMoney());
		gm.setPoundage(gmMoneyRecord.getPoundage());
		gm.setGmUser(gmMoneyRecord.getGmUser());
		gm.setCreateDate(new DateUtil().toTimeString());	
		gm.setBankOrder(new DateUtil().toGetMoneyNum());
		gm.setOrderNum(new DateUtil().toGetMoneyNum());
		if(i==3){
			gm.setCountInfo(gmMoneyRecord.getCountInfo());
			gm.setCountName(gmMoneyRecord.getCountName());
			gm.setCountNumber(gmMoneyRecord.getCountNumber());
		}
		if(i==1){
			gm.setZfbCountName(gmMoneyRecord.getZfbCountName());
			gm.setZfbCountNumber(gmMoneyRecord.getZfbCountNumber());
		}
		
		System.out.println(new DateUtil().toGetOrderNum());
		gmMoneyRecordDAO.saveOrUpdate(gm);
	}
	
//	public Long findNewValueOrder(GmUser guser){
//	List list = gmMoneyRecordDAO.getNewValueOrder(guser.getUserName());
//	if(list.size()>0){
//		Long l=(Long)list.get(0);
//		return l;
//	}
//	return null;
//}
	
	public List getFundDetial(GmMoneyRecord  gm){
		List list = gmMoneyRecordDAO.findFundDetial(gm);
		if(list.size()>0){
			return list;
		}
		return null;
	}
	
	public List getCashDraw(){
		List list = gmMoneyRecordDAO.findCashDraw();
		if(list.size()>0){
			return switchMoneyRecordValues(list);
		}
		return null;
	}
	
	public String findCashDrawByGetTypeToday(int userid){
		List list = gmMoneyRecordDAO.findCashDrawByGetTypeToday(userid);
		System.out.println("findCashDrawByGetTypeToday="+list.size());
		if(list.size()<=0){
			return "success";
		}
		return "fail";
	}
	
	public List getTheCashDraw(String qq,String username){
		List list = gmMoneyRecordDAO.findTheCashDraw(qq,username);
		if(list.size()>0){
			return switchMoneyRecordValues(list);
		}
		return null;
	}
	
	public List getChargeValue(){
		List list = gmMoneyRecordDAO.findChargeValue();
		if(list.size()>0){
			return switchMoneyRecordValues(list);
		}
		return null;
	}
	
	public List getdeposit(){
		List list = gmMoneyRecordDAO.finddeposit();
		if(list.size()>0){
			System.out.println("getdeposit"+list.size());
			return list;
		}
		return null;
	}
	
	public List getTheDeposit(String qq,String username){
		List list = gmMoneyRecordDAO.findTheDeposit(qq,username);
		if(list.size()>0){
			System.out.println("getdeposit"+list.size());
			return list;
		}
		return null;
	}
	
	public List getTheChargeValue(String qq,String username){
		List list = gmMoneyRecordDAO.findTheChargeValue(qq,username);
		if(list.size()>0){
			return switchMoneyRecordValues(list);
		}
		return null;
	}
	
	public void saveMoneyRecord(GmMoneyRecord gm){
		System.out.println(gm.getId());
		gmMoneyRecordDAO.saveOrUpdate(gm);
	}
	
	public void saveDeposit(GmUser guser,Double getMoney){
		GmMoneyRecord gm = new GmMoneyRecord();
		gm.setGmUser(guser);
		gm.setGetMoney(getMoney);
		gm.setGetType(new Integer(3));
		gm.setCreateDate(new DateUtil().toTimeString());
		gm.setId(null);
		gm.setState(new Integer(1));
		gmMoneyRecordDAO.saveOrUpdate(gm);
	}
	
	private List switchMoneyRecordValues(List list) {
		List result = new ArrayList();
		if (list.size() > 0) {
		for (int i = 0; i < list.size(); i++) {
			GmMoneyRecord gm = (GmMoneyRecord) list.get(i);
			switch (gm.getState().intValue()) {
			//1未处理2成功�ɹ�
			case 1:
				gm.setStateValue("未处理");
				break;
			case 2:
				gm.setStateValue("成功");
				break;
			}
			switch (gm.getGetType().intValue()) {
			//1充值2取现�
			case 1:
				gm.setGetTypeValue("充值");
				break;
			case 2:
				gm.setGetTypeValue("取现");
				break;
			case 3:
				gm.setGetTypeValue("取回押金");
				break;
			}
			result.add(gm);
			gm = null;
		}
	}

	return result;
}
 
}
